<?php
/**
 * @title 78. 子集 - 递归
 * @author start2004
 */

// ini_set("memory_limit", "128M");

class Solution {

    /**
     * @param Integer[] $nums
     * @return Integer[][]
     */
    function subsets($nums) {
        /**
         * @since 2020-09-21 取一个数
         */
        $num = array_pop($nums);

        if($num === null){
            $result = [[]];
        } else {
            /**
             * @since 2020-09-21 没有num
             */
            $result = self::subsets($nums);

            /**
             * @since 2020-09-21 有num
             */
            for($i=0, $iMax=count($result)-1; $i<=$iMax; $i++){
                $data = $result[$i];
                $data[] = $num;
                $result[] = $data;
            }
        }

        /**
         * @return
         */
        return $result;
    }
}



/**
 * @url http://127.0.0.1/leetcode/202008/2020.08.07_6.php
 */
$datas = [
    [1,2,3],
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->subsets($data);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
